home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / BlobMgr / Library Folder / Shuffle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  1.8 KB  |  69 lines  |  [TEXT/KAHL]

  1. # include    "BlobMgr.h"
  2.  
  3.  
  4. /*
  5.  * Shuffle the locations of the blobs in the given set.  If it is
  6.  * undesirable to show all the redrawing that takes place during
  7.  * this, HideBlobSet() should be called before ShuffleBlobSet(), and
  8.  * ShowBlobSet() after.
  9.  *
  10.  * ShuffleBlobSet() deals with the following problem.  Suppose two blobs
  11.  * to be switched are both visible.  The first is moved, i.e., hidden
  12.  * and redrawn at the location of the second.  Then the second is moved,
  13.  * i.e., hidden and redrawn at the previous location of the first.
  14.  * But moving the second blob erases the newly drawn first blob!  To
  15.  * avoid this, ShuffleBlobset() hides the first blob before moving them,
  16.  * and redraws it afterward.
  17.  
  18.  * ShuffleBlobSet() usually results in an update event being generated
  19.  * since hiding a blob adds its region to the update region for the
  20.  * window.  ValidRect() can be called (with the window's portRect)
  21.  * to defeat it.
  22.  *
  23.  * The static region is often empty, which is why the drag regions are used
  24.  * to determine the offsets.
  25.  */
  26.  
  27. pascal void
  28. ShuffleBlobSet (BlobSetHandle bSet)
  29. {
  30. BlobHandle    b1, b2;
  31. short    size, h, v;
  32. Boolean    vis1 = false;
  33.  
  34.     size = BlobSetSize (bSet);
  35.     for (b1 = FirstBlob (bSet); b1 != nil; b1 = NextBlob (b1))
  36.     {
  37.         b2 = GetBlobHandle (bSet, BlobRand (size - 1));
  38.         h = BDragBox (b1).left - BDragBox (b2).left;
  39.         v = BDragBox (b1).top - BDragBox (b2).top;
  40.         if (BlobEnabled (b1))
  41.         {
  42.             HideBlob (b1);
  43.             vis1 = true;
  44.         }
  45.         OffsetBlob (b1, inFullBlob, -h, -v);
  46.         OffsetBlob (b2, inFullBlob, h, v);
  47.         if (vis1)
  48.             ShowBlob (b1);
  49.     }
  50. }
  51.  
  52.  
  53. /*
  54.  * Shuffle the globs attached to the blobs in the given set.
  55.  */
  56.  
  57. pascal void
  58. ShuffleGlobSet (BlobSetHandle bSet)
  59. {
  60. BlobHandle    b;
  61. short    size;
  62.  
  63.     size = BlobSetSize (bSet);
  64.     for (b = FirstBlob (bSet); b != nil; b = NextBlob (b))
  65.     {
  66.         SwapGlob (b, GetBlobHandle (bSet, BlobRand (size-1)));
  67.     }
  68. }
  69.